package com.ruoyi.schedule.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.stuinfo.domain.Abnormalbehaviorreport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.schedule.domain.StudentCourseSchedule;
import com.ruoyi.schedule.service.IStudentCourseScheduleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生课程计划Controller
 *
 * @author dongyv
 * @date 2025-05-15
 */
@RestController
@RequestMapping("/schedule/schedule")
public class StudentCourseScheduleController extends BaseController
{
    @Autowired
    private IStudentCourseScheduleService studentCourseScheduleService;

    /**
     * 查询学生课程计划列表
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentCourseSchedule studentCourseSchedule)
    {

        String teacherId=getUsername();
        boolean hasH = teacherId.contains("H");
        if("admin".equals(teacherId))
        {
            //管理员
            startPage();
            List<StudentCourseSchedule> list = studentCourseScheduleService.selectStudentCourseScheduleList(studentCourseSchedule);
            return getDataTable(list);
        }
        else
        {
            //班主任
            teacherId=teacherId.replace("H", "");
            startPage();
            List<StudentCourseSchedule> list = studentCourseScheduleService.selectStudentCourseScheduleList_handteacher(teacherId);
            return getDataTable(list);
        }


    }

    /**
     * 导出学生课程计划列表
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:export')")
    @Log(title = "学生课程计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentCourseSchedule studentCourseSchedule)
    {
        List<StudentCourseSchedule> list = studentCourseScheduleService.selectStudentCourseScheduleList(studentCourseSchedule);
        ExcelUtil<StudentCourseSchedule> util = new ExcelUtil<StudentCourseSchedule>(StudentCourseSchedule.class);
        util.exportExcel(response, list, "学生课程计划数据");
    }

    /**
     * 获取学生课程计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(studentCourseScheduleService.selectStudentCourseScheduleById(id));
    }

    /**
     * 新增学生课程计划
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:add')")
    @Log(title = "学生课程计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentCourseSchedule studentCourseSchedule)
    {
        return toAjax(studentCourseScheduleService.insertStudentCourseSchedule(studentCourseSchedule));
    }

    /**
     * 修改学生课程计划
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:edit')")
    @Log(title = "学生课程计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentCourseSchedule studentCourseSchedule)
    {
        return toAjax(studentCourseScheduleService.updateStudentCourseSchedule(studentCourseSchedule));
    }

    /**
     * 删除学生课程计划
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:remove')")
    @Log(title = "学生课程计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(studentCourseScheduleService.deleteStudentCourseScheduleByIds(ids));
    }
}
